var e = require("../../../@babel/runtime/helpers/defineProperty"), t = getApp();

Page({
    data: {
        bearerId: "",
        bearerType: 0,
        checked: !1,
        inputList: [],
        formData: {}
    },
    onLoad: function(e) {
        if (void 0 !== e.id) {
            var t = e.id;
            this.setData({
                bearerId: t
            }), this.getDetailData(t);
        }
    },
    onShow: function() {
        this.inputListFun(this.data.bearerType);
    },
    getDetailData: function(e) {
        var a = this, i = t.getNetAddresss("plugin.invoice.frontend.rise.edit");
        t._getNetWork({
            url: i,
            data: {
                id: e
            },
            success: function(e) {
                var i = e.data;
                if (1 != i.result) return t.tips(i.msg);
                a.setData({
                    formData: i.data,
                    bearerType: i.data.type
                }), a.inputListFun(i.data.type);
            }
        });
    },
    changeRoadio: function(e) {
        this.setData({
            bearerType: e.detail,
            formData: {}
        }), this.inputListFun(e.detail);
    },
    inputListFun: function(e) {
        var t = 1 == e ? [ {
            place: "请填写单位名称",
            label: "单位",
            model: "collect_name"
        }, {
            place: "请填写纳税人识别号",
            label: "税号",
            model: "tax_num"
        }, {
            type: "divider",
            label: "分割线"
        }, {
            place: "请填写单位开户银行（选填）",
            label: "开户银行",
            model: "bank"
        }, {
            place: "请填写单位银行账号（选填）",
            label: "银行账号",
            model: "bank_admin"
        }, {
            place: "请填写注册地址（选填）",
            label: "注册地址",
            model: "address"
        }, {
            place: "请填写注册电话（选填）",
            label: "注册电话",
            model: "mobile"
        } ] : [ {
            place: "请填写需要开具发票的姓名",
            label: "发票抬头",
            model: "collect_name"
        } ];
        this.setData({
            inputList: t
        });
    },
    chagenInput: function(t) {
        var a = t.currentTarget.dataset.model, i = t.detail.replace(/\s+/g, "");
        this.setData(e({}, "formData." + a, i));
    },
    changeSwitch: function(t) {
        this.setData(e({}, "formData.is_default", t.detail));
    },
    saveData: function() {
        if (t._isTextEmpty(this.data.formData.collect_name)) return "0" == this.data.bearerType ? t.tips("发票抬头不能为空！") : t.tips("单位名称不能为空！");
        if (1 == this.data.bearerType && t._isTextEmpty(this.data.formData.tax_num)) return t.tips("纳税识别号不能为空！");
        var e = "", a = {}, i = this.filterFormData();
        this.data.bearerId ? (e = t.getNetAddresss("plugin.invoice.frontend.rise.edit"), 
        a.id = this.data.bearerId, a.data = i) : (e = t.getNetAddresss("plugin.invoice.frontend.rise.store"), 
        a.data = i), t._postNetWork({
            url: e,
            data: a,
            success: function(e) {
                var a = e.data;
                t.tips(a.msg), 1 == a.result && wx.redirectTo({
                    url: "/packageI/invoice/invoiceCenter/invoiceCenter?type=-1"
                });
            }
        });
    },
    filterFormData: function() {
        var e = this.data.formData, t = e.collect_name, a = e.tax_num, i = e.bank, r = e.bank_admin, n = e.address, s = e.mobile, d = e.is_default;
        return 1 == this.data.bearerType ? {
            type: this.data.bearerType,
            collect_name: t,
            tax_num: a,
            bank: i,
            bank_admin: r,
            address: n,
            mobile: s,
            is_default: d
        } : {
            type: this.data.bearerType,
            collect_name: t,
            is_default: d
        };
    },
    onShareAppMessage: function() {}
});